package main

import (
	"github.com/kataras/iris"

	"gitee.com/yinxulai/PrivateToolServer/restful/controllers"
	"gitee.com/yinxulai/PrivateToolServer/services/config"
	"github.com/iris-contrib/middleware/cors"
	"github.com/kataras/iris/middleware/logger"
	"github.com/kataras/iris/middleware/recover"
)

func main() {
	app := iris.New()
	app.Favicon("./static/favicon.ico") //设置ico
	app.StaticWeb("/static", "./assets")
	app.Logger().SetLevel("debug")
	app.Use(recover.New())
	app.Use(logger.New())
	config.LoadJSON("./config.json")
	crs := cors.New(cors.Options{
		AllowOriginFunc:  func(origin string) bool { return true }, // 允许跨域
		AllowCredentials: true,                                     // 允许携带cookie
	})
	restful := app.Party("/restful", crs).AllowMethods().AllowMethods(iris.MethodOptions) //请求方法检测
	restful.Put("/v1/squashpicture", controllers.Squash)                                  //创建图片压缩任务
	restful.Get("/v1/pullsquashpicture", controllers.PullSquash)                          //查看获取结果
	restful.Put("/v1/convertpicture", controllers.Convert)                                //创建图片格式转换任务
	restful.Get("/v1/pullconvertpicture", controllers.PullConvert)                        //查看获取结果
	restful.Get("/v1/detectpicture", controllers.Detect)                                  //查看图片处理状态

	app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}
